<%@ page language="java" contentType="text/html; charset=utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<!-- 王奇 -->
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="keywords" content="jquery,ui,easy,easyui,web">
<meta name="description"
	content="easyui help you build your web page easily!">
<title>票务管理</title>
<link rel="stylesheet" type="text/css"
	href="../js/easyui/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="../js/easyui/themes/icon.css">
<link rel="stylesheet" type="text/css" href="../js/easyui/demo/demo.css">
<script type="text/javascript" src="../js/easyui/jquery.min.js"></script>
<script type="text/javascript" src="../js/easyui/jquery.easyui.min.js"></script>
<script type="text/javascript" src="../js/easyui/locale/easyui-lang-zh_CN.js"></script>
<script type="text/javascript" src="../js/ticket/checkTicket.js"></script>
<style type="text/css">
#fm {
	margin: 0;
	padding: 10px 30px;
}

.ftitle {
	font-size: 14px;
	font-weight: bold;
	color: #666;
	padding: 5px 0;
	margin-bottom: 10px;
	border-bottom: 1px solid #ccc;
}

.fitem {
	margin-bottom: 5px;
}

.fitem label {
	display: inline-block;
	width: 80px;
}
</style>


<script type="text/javascript">
	var url;
	function newUser() {
		$('#dlg').dialog('open').dialog('setTitle', '票务管理');
		$('#fm').form('clear');
		url = '../adminServlet?param=add'; //保存用户的url
		('#dg').datagtid('load');
	}
	function editUser() {
		var row = $('#dg').datagrid('getSelected');
		if (row) {
			$('#dlg').dialog('open').dialog('setTitle', 'Edit User');
			document.getElementById('prices').value = row.price;
			document.getElementById('trains').value = row.train;
			document.getElementById('splaces').value = row.splace;
			document.getElementById('eplaces').value = row.eplace;
			document.getElementById('times').value = row.times;
			document.getElementById('numss').value = row.nums;
			var id=row['id'];
			url = '../adminServlet?param=update&id='+id;
			$('#dg').datagrid('load'); 																		

		}
	}
	function saveUser() {
		$('#fm').form('submit', {
			url : url,
			onSubmit : function() {
				return $(this).form('validate');
			},
		 	success : function(result) {
				//var date = eval('(' + result + ')');
				alert(result.success);
				if (result.success) {
					$('#dlg').dialog('close'); // close the dialog
					$('#dg').datagrid('reload');  // reload the user data
				} else {
					$.messager.show({
						title : 'Error',
						msg : result.msg
					});
				}
			} 
		});
	}
	function removeUser() {
		var row = $('#dg').datagrid('getSelected');
		if (row) {
			$.messager.confirm('操作提示',
					'你确定要删除吗?', function(r) {
						if (r) {
							$.post('../adminServlet?param=delete', {id : row['id']},
							 function(result) {
								if (result.success) {
                                    $('#dg').datagrid('load'); 
                                    $.messager.alert("操作提示", "操作成功！"); 
                                     
								} else {
								
									 $.messager.alert("操作提示", "操作失败！"); 
								}
							}, 'json');
						}
					});
		       }
	}
	
	 Date.prototype.format = function(format) {  
	        var o = {  
	            "M+": this.getMonth() + 1, // month  
	            "d+": this.getDate(), // day  
	            "h+": this.getHours(), // hour  
	            "m+": this.getMinutes(), // minute  
	            "s+": this.getSeconds(), // second  
	            "q+": Math.floor((this.getMonth() + 3) / 3),
	            "S": this.getMilliseconds()  
	            // millisecond  
	        }  
	        if (/(y+)/.test(format))  
	            format = format.replace(RegExp.$1, (this.getFullYear() + "")  
	                .substr(4 - RegExp.$1.length));  
	        for (var k in o)  
	            if (new RegExp("(" + k + ")").test(format))  
	                format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));  
	        return format;  
	    }  
	 
	$(document).ready(function () {
		$('#dg').datagrid({
		    pagination:true,
		    fitColumns:true,
		    singleSelect:true,
		    rownumbers:true,
		    cache: false,
		    url:'../GetTicketServlet',
		    columns:[[
		        {field:'id',title:'ID',width:30},
		        {field:'train',title:'车次',width:30},
		        {field:'times',title:'时间',width:30,formatter:formatDatebox},
		        {field:'price',title:'价格',width:30},
		        {field:'splace',title:'始发地',width:30},
		        {field:'eplace',title:'终点',width:30},
		        {field:'nums',title:'票数',width:30}
		    ]]
		});

	function formatDatebox(value) {  
	    if (value == null || value == '') {  
	        return '';  
	    }  
	    var dt;  
	    if (value instanceof Date) {  
	        dt = value;  
	    } else {  
	        dt = new Date(value);  
	    }  
	  
	    return dt.format("yyyy-MM-dd hh:mm:ss"); //扩展的Date的format方法(上述插件实现)  
	}
});
	$(document).ready(function () {
	 var p = $('#dg').datagrid('getPager');  
	                $(p).pagination({  
	                pageSize: 10,//每页显示的记录条数，默认为5  
	                pageList: [10, 20 ,30],//可以设置每页记录条数的列表  
	                beforePageText: '第',//页数文本框前显示的汉字  
	                afterPageText: '页    共 {pages} 页',  
	                displayMsg: '当前显示 {from} - {to} 条记录   共 {total} 条记录'
	            });  
	
	}); 
	
 	
	 $(document).ready(function(){  
          $("#searchBtn").click(function(){  
          
              $('#dg').datagrid({
              url :'../SearchTicketServlet?params='+$("#searchs").val(),
              pagination:true,
		      fitColumns:true,
		      singleSelect:true,
		      rownumbers:true,
		      cache: false,
              columns:[[
		        {field:'id',title:'ID',width:30},
		        {field:'train',title:'车次',width:30},
		        {field:'times',title:'时间',width:30},
		        {field:'price',title:'价格',width:30},
		        {field:'splace',title:'始发地',width:30},
		        {field:'eplace',title:'终点',width:30},
		        {field:'nums',title:'票数',width:30}
		    ]]
        });
            });  
        }); 
   
		/*../adminServlet?param=serach"+"&params="+$("[name=searchs]").val()*/
	/* 	 $(document).ready(function(){
         $("#searchBtn").click(function(){
         alert("!")
             $.ajax({
                  type: "POST",
                  url: "../AdminLogin.jsp",
                  dataType: "text"//类型
             });
         });
     }); */
</script>
</head>
<body>
	<h2>票务管理</h2>
	<div class="demo-info" style="margin-bottom: 10px">
		<div class="demo-tip icon-tip"> </div>
		<div>点击下面的功能按钮，实现对票务的操作</div>
	</div>
	<table id="dg" title="票务管理" class="easyui-datagrid"
		style="width: 1041px; height: 430px" toolbar='#toolbar'>
		<!-- <thead>
			<tr>
				<th field="price" width="30">价格</th>
				<th field="train" width="30">车次</th>
				<th field="times" width="20" formatter: formatDatebox>时间</th>
				<th field="splace" width="50" >始发地</th>
				<th field="eplace" width="50">终点</th>
				<th field="nums" width="50">票数</th>
			</tr>
		</thead> -->
	</table>
	<div id="toolbar">
	<div>
		    <a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true"
			onclick=newUser();>添加</a> <a href="#" class="easyui-linkbutton"
			iconCls="icon-edit" plain="true" onclick=editUser();>修改</a> 
			<ahref="#" class="easyui-linkbutton" iconCls="icon-remove" plain="true"
			onclick=removeUser();>删除</a>&nbsp;&nbsp;&nbsp;
	</div>
	   <div>
			请输入关键字: 
			<input class="easyui-textbox" style="width:100px"  name="searchs" id="searchs">
            <button id="searchBtn" >查询</button>  
        </div>  
	</div>	
	  
   </div>  
	<div id="dlg" class="easyui-dialog"
		style="width: 400px; height: 380px; padding: 10px 20px" closed="true"
		buttons="#dlg-buttons">
		<div class="ftitle">票务信息</div>
		<form id="fm" method="post" novalidate>

			<div class="fitem">
				<label> 价格: </label> <input name="price" class="easyui-validatebox" id="prices"
					data-options="required:true,validType:'price'">
			</div>
			<div class="fitem">
				<label> 车次: </label> <input name="train" id="trains"
					class="easyui-validatebox" data-options="required:true,validType:'train'">
			</div>
			<div class="fitem">
				<label> 始发地: </label> <input name="splace" class="easyui-validatebox" id="splaces"
					required="true">
			</div>
			<div class="fitem">
				<label> 终点: </label> <input name="eplace" id="eplaces"
					class="easyui-validatebox" required="true">
			</div>
			<div class="fitem">
				<label> 时间: </label> <input class="easyui-datetimebox"
					name="times" data-options="required:true,validType:'time'" id="times"
					style="width:150px">
			</div>
			<div class="fitem">
				<label> 票数: </label> <input name="nums" id="numss"
					class="easyui-validatebox" data-options="required:true,validType:'nums'">
			</div>
		</form>
	</div>
	<div id="dlg-buttons">
		<a href="#" class="easyui-linkbutton" iconCls="icon-ok"
			onclick=saveUser();>保存</a> <a href="#" class="easyui-linkbutton"
			iconCls="icon-cancel" onclick="javascript:$('#dlg').dialog('close');">取消</a>
	</div>
</body>
</html>